package com.lxmes.base.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.base.domain.JcItembzinfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.base.domain.JcProductionLine;
import com.lxmes.base.service.IJcProductionLineService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 生产线信息维护Controller
 * 
 * @author ruoyi
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/base/productionLine")
public class JcProductionLineController extends BaseController
{
    @Autowired
    private IJcProductionLineService jcProductionLineService;

    /**
     * 查询生产线信息维护列表
     */
    @PreAuthorize("@ss.hasPermi('base:productionLine:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcProductionLine jcProductionLine)
    {
        startPage();
        List<JcProductionLine> list = jcProductionLineService.selectJcProductionLineList(jcProductionLine);
        return getDataTable(list);
    }

    /**
     * 导出生产线信息维护列表
     */
    @PreAuthorize("@ss.hasPermi('base:productionLine:export')")
    @Log(title = "生产线信息维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcProductionLine jcProductionLine)
    {
        List<JcProductionLine> list = jcProductionLineService.selectJcProductionLineList(jcProductionLine);
        ExcelUtil<JcProductionLine> util = new ExcelUtil<JcProductionLine>(JcProductionLine.class);
        util.exportExcel(response, list, "生产线信息维护数据");
    }

    /**
     * 获取生产线信息维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:productionLine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jcProductionLineService.selectJcProductionLineById(id));
    }

    /**
     * 新增生产线信息维护
     */
    @PreAuthorize("@ss.hasPermi('base:productionLine:add')")
    @Log(title = "生产线信息维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcProductionLine jcProductionLine)
    {
        return toAjax(jcProductionLineService.insertJcProductionLine(jcProductionLine));
    }

    /**
     * 修改生产线信息维护
     */
    @PreAuthorize("@ss.hasPermi('base:productionLine:edit')")
    @Log(title = "生产线信息维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcProductionLine jcProductionLine)
    {
        return toAjax(jcProductionLineService.updateJcProductionLine(jcProductionLine));
    }

    /**
     * 删除生产线信息维护
     */
    @PreAuthorize("@ss.hasPermi('base:productionLine:remove')")
    @Log(title = "生产线信息维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcProductionLineService.deleteJcProductionLineByIds(ids));
    }

    @Log(title = "生产线信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<JcProductionLine> util = new ExcelUtil<>(JcProductionLine.class);
        List<JcProductionLine> proLineList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = jcProductionLineService.imporIteminfo(proLineList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<JcProductionLine> util = new ExcelUtil<>(JcProductionLine.class);
        util.importTemplateExcel(response,"生产线数据");
    }
}
